package com.woniu.supermarket.web;



import com.woniu.supermarket.result.ResultResponse;
import com.woniu.supermarket.service.ISalesReturnDetailService;
import com.woniu.supermarket.vo.SalesReturnDetailVo;
import com.woniu.supermarket.vo.SalesReturnDetailVoList;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("salesReturnDetail")
@Api(value = "销售详情订单操作")
@Slf4j
public class SalesReturnDetailController {

    @Autowired
    ISalesReturnDetailService iSalesReturnDetailService;

    @GetMapping("/showSalesReturnDetail/{id}")
    @ApiOperation(value = "查询销售退货订单详情操作")
    public ResultResponse<List<SalesReturnDetailVo>> showSalesReturnDetail(@PathVariable("id")Integer id){

        ResultResponse<List<SalesReturnDetailVo>> result = null;
        try {
            List<SalesReturnDetailVo> salesReturnDetailVos = iSalesReturnDetailService.quaryAll(id);
            result = new ResultResponse<>(200,"查询销售订单详情成功",salesReturnDetailVos);
        }catch (RuntimeException e){
            e.printStackTrace();
            result = new ResultResponse<>(201,"查询销售订单详情失败");
        }
        return result;
    }


    @PutMapping("/resetTotal")
    @ApiOperation(value = "重置小计")
    public ResultResponse<Void> resetTotal(@RequestBody SalesReturnDetailVoList list){
        ResultResponse<Void> result = null;
        try {

            list.printlist();
            iSalesReturnDetailService.resetTotalBatch(list.getTotalWithIdList());
            result = new ResultResponse<>(200,"重置小计成功");
        }catch (RuntimeException e){
            e.printStackTrace();
            result = new ResultResponse<>(201,"重置小计失败");
        }
        return result;
    }

}
